package com.genauth.sys.controller;

import com.genauth.sys.entity.PageResponse;
import com.genauth.sys.entity.test.PageQueryBean;
import com.genauth.sys.entity.test.UserInfoBean;
import com.genauth.sys.entity.test.UserInfoQueryBean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping(value = "/genauth/testData")
public class TestDataController {

    @ResponseBody
    @RequestMapping(value = "/getTestData.do", produces = "application/json;charset=UTF-8", method = {RequestMethod.POST})
    public PageResponse testData(HttpServletRequest request, PageQueryBean pb, UserInfoQueryBean userInfoQueryBean) throws Exception {
        PageResponse res = new PageResponse();

        List<UserInfoBean> queryRes = new ArrayList<>();
        for(int i = 0 ; i < pb.getLimit(); i ++){
            UserInfoBean ui = new UserInfoBean();
            ui.setId(""+i);
            ui.setName(""+pb.getPage());
            ui.setRemark("startindex :"+(pb.getPage()*pb.getLimit())+";endindex : "+(pb.getPage()*pb.getLimit()+pb.getLimit()));
            ui.setBirthday("20200220");
            ui.setSalary("100.1");
            ui.setSecInfo("secret info");

            queryRes.add(ui);
        }
        res.setRspData(queryRes);
        return res;
    }

    @ResponseBody
    @RequestMapping(value = "/insertTestData.do", produces = "application/json;charset=UTF-8", method = {RequestMethod.POST})
    public PageResponse insertTestData(HttpServletRequest request, PageQueryBean pb, UserInfoBean userInfoBean) throws Exception {
        Thread.sleep(1000);
        return new PageResponse();
    }

    @ResponseBody
    @RequestMapping(value = "/updateTestData.do", produces = "application/json;charset=UTF-8", method = {RequestMethod.POST})
    public PageResponse updateTestData(HttpServletRequest request, PageQueryBean pb, UserInfoBean userInfoBean) throws Exception {
        Thread.sleep(1000);
        return new PageResponse();
    }
}
